package com.tjw.ec.upms.controller;

import com.tjw.ec.common.core.util.PageUtils;
import com.tjw.ec.common.core.util.R;
import com.tjw.ec.common.core.util.Response;
import com.tjw.ec.upms.api.entity.ActionEntity;
import com.tjw.ec.upms.api.feign.RemoteActionService;
import com.tjw.ec.upms.service.ActionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 控制动作层： 系统中所有操作的动作表;
 *
 * @author T-junwen
 * @email t-junwen@foxmail.com
 * @date 2019-07-27 17:28:58
 */
@Slf4j
@RestController
@RequestMapping("action")
public class ActionController {

    @Autowired
    private ActionService actionService;

    @Autowired
    private RemoteActionService remoteActionService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = actionService.queryPage(params);
        return R.data(page);
    }

    /**
     * 远程调用测试列表接口
     */
    @GetMapping("/list2")
    public R list2(@RequestParam Map<String, Object> params) {
        Response<PageUtils<ActionEntity>> list = remoteActionService.page(params);
        log.info(list.getMsg());
        log.info(String.valueOf(list.getCode()));
        return R.data(list.getData());
    }
    /**
     * 信息
     */
    @GetMapping("/info2/{actionId}")
    public R info2(@PathVariable("actionId") String actionId) {
        Response<ActionEntity> info = remoteActionService.info(actionId);
        return R.data(info.getData());
    }

    /**
     * 信息
     */
    @GetMapping("/info/{actionId}")
    public R info(@PathVariable("actionId") String actionId) {
            ActionEntity action = actionService.getById(actionId);
        return R.data(action);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody ActionEntity action) {
            actionService.save(action);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody ActionEntity action) {
            actionService.updateById(action);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestParam String[]ids) {
            actionService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
